<%@ page language="java" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="s" uri="http://www.springframework.org/tags" %>
<%@ page isELIgnored="false" %>
<%
	String path = request.getContextPath();
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<link rel="stylesheet" href="<s:url value="/resources"/>/css/jingj.css" type="text/css" />
<script type="text/javascript" src="<s:url value="/resources"/>/js/jquery-1.7.2.min.js"></script>
</head>

<body>
    <form name="form1" method="post" action="" id="aspnetForm" enctype="multipart/form-data">
       <div class="wrap">
        <div class="jj_bt">
            <span id="lbiaot">${jjinfo.baodrdwmc}-<c:if test="${jjinfo.maimlx=='6'}">拍卖</c:if><c:if test="${jjinfo.maimlx=='5'}">招标</c:if></span>
        </div>
        <table class="jj_tb1" width="100%">
            <tbody><tr style="line-height: 80px;">
                <td align="right" bgcolor="#fff2e2" width="107">
                    <strong>最新价：</strong><input id="dqjg" type="hidden" name="dqjg" value="${dqjg}" />
                </td>
                <td width="252">
                    <span>
                        <span id="zuixj" style="display:inline-block;width:163px;">${dqjg}</span></span><b>(元/吨)</b>
                </td>
                <td align="right" bgcolor="#fff2e2" width="110">
                    <strong>倒计时：</strong>
                </td>
                <td id="daojishijian" width="280"><div class="colockbox" id="colockbox2" style="display:none"> <b>马上开始</b></div><div class="colockbox" id="colockbox3" style="display:none"><b>已经结束</b></div><div class="colockbox" id="colockbox1"><div style="display:none" ><span class="day">00</span> <b>天</b><span class="hour">00</span><b>小时</b></div><span class="minute">00</span><b>分钟</b><span  class="second">00</span><b>秒</b> </div></td>
            </tr>
        </tbody></table>
        <script type="text/javascript">
        
$(function(){
	 //开始时间 
  	 var sk_time = "${jjinfo.kaishshj}";
  	 //结束时间
	 var sj_time = "${jjinfo.jieshshj}";
	 //当前结束时间
	 var sd_time = "${dangqjiesshj}";
	 //当前系统时间
	 var sx_time = "${jysj}";
	 
  	 var k_time = new Date(sk_time.replace(/-/g,"/")).getTime();
	 var j_time = new Date(sj_time.replace(/-/g,"/")).getTime();
	 var d_time = new Date(sd_time.replace(/-/g,"/")).getTime();
	 var x_time = new Date(sx_time).getTime();
	 
	if(k_time>x_time){
	    $("#colockbox2").css('display','block'); 
	    $("#colockbox3").css('display','none'); 
	    $("#colockbox1").css('display','none'); 
	    //$("#btchujia").attr('disabled',"true");
	   
	 }else if(x_time>d_time){
		//$("#colockbox1").append("已经结束"); 
		    $("#colockbox3").css('display','block'); 
		    $("#colockbox2").css('display','none'); 
		    $("#colockbox1").css('display','none'); 
		    //$("#btchujia").attr('disabled',"true");
		     // $("#btchujia").removeAttr("disabled"); 
		   
	 }else{
		
		    $("#colockbox1").css('display','block'); 
		    $("#colockbox3").css('display','none'); 
		    $("#colockbox2").css('display','none'); 
		    //$("#btchujia").removeAttr("disabled"); 
	 countDown(d_time,x_time,"#colockbox1");
	 }
	     
	     var timer3;
	     function show1(str){
	    	 
	    	 x_time=x_time+1000;
	    	 // alert(time1+"-"+time2);
	    	 if (x_time>d_time){
	    		$("#colockbox1").css('display','block'); 
	 		    $("#colockbox3").css('display','none'); 
	 		    $("#colockbox2").css('display','none');
	 		  //$("#btchujia").attr('disabled',"true");
			   //$("#btchujia").removeAttr("disabled"); 
	 		  clearInterval(timer3); 
	 		  countDown(d_time,x_time,"#colockbox1");
	    	 }
	    	}
	     timer3=setInterval(show1,1000);     
	     read();
 //	countDown("2014/10/1 10:00:00","2014/10/1 9:45:00","#colockbox1");
});
function showca(){ 
	var chujia = $("#chuj").val();
	var dqjg = $("#dqjg").val();
	//alert(chujia);
    var MinPrice = "${jjinfo.zuidj}";
    var MaxPrice = "${jjinfo.zuigj}";	
	if(parseInt(chujia)<parseInt(MinPrice) || parseInt(chujia)>parseInt(MaxPrice)){
		alert("价格超出了范围！");
		return false;
	}
	//if("${jjinfo.maimlx}"=="6"){
		//if(chujia<dqjg){
		//	alert("价格不能低于");
		//}
	//}
	var f = document.forms['form1'];    
    var url = "http://localhost:8080/jjjyService/comet/setComet";
   //alert(url); 
    $.post(url,$(f).serialize(),function(data){
   	 if("" != data){
     //alert(data);
   	 }
   },"text"		
   
   ); 
    $("#msg").val("");
    //alert($("#msg").val());
}  
function read(){  
    var url = "http://localhost:8080/jjjyService/comet/getComet";
    $.ajax({  
       type: "GET",  
       url: url,  
       success: function(data){  
         if("ERROR" != data){ 
         
        	 var json =eval('(' + data + ')');
        	  //alert(json.dealtime);
        	  $("#chuj").val(json.newprice);
        	  $("#dqjg").val(json.newprice);
        	  
        	  $("#zuixj").html(json.newprice);
             $("#jjtab1 tr:eq(1)").after("<tr bgcolor='#fffbd5'><td>"+json.dealer+"</td><td>"+json.newprice+"</td><td>"+json.dealtime+"</td></tr>");
        	 $("#jjtab2").html(json.deallist);
 
          	 var sk_time = "${jjinfo.kaishshj}";
        	 var sj_time = "${jjinfo.jieshshj}";
        	 //当前结束时间
        	 var sd_time = json.endtime;
        	 //当前系统时间
        	 var sx_time =json.systime;
        	 
          	 var k_time = new Date(sk_time.replace(/-/g,"/")).getTime();
        	 var j_time = new Date(sj_time.replace(/-/g,"/")).getTime();
        	 
        	 var d_time = new Date(sd_time.replace(/-/g,"/")).getTime();
        	 
    	     if(k_time>d_time){
    	 	   // $("#colockbox2").css('display','block'); 
    	 	    //$("#colockbox3").css('display','none'); 
    	 	    //$("#colockbox1").css('display','none'); 
 	 		   //$("#btchujia").attr('disabled',"true");
			   //$("#btchujia").removeAttr("disabled"); 
    	 	 }else if(j_time<d_time){
    	 		// alert(j_time+"-"+d_time);
    	 		//$("#colockbox1").append("已经结束"); 
    	 		    //$("#colockbox3").css('display','block'); 
    	 		    //$("#colockbox2").css('display','none'); 
    	 		    //$("#colockbox1").css('display','none'); 
    	 		   //$("#btchujia").attr('disabled',"true");
    	 	 }else{
    	 		    //$("#colockbox1").css('display','block'); 
    	 		    //$("#colockbox3").css('display','none'); 
    	 		    //$("#colockbox2").css('display','none');  
    	 		   //$("#btchujia").removeAttr("disabled");
    	 	 countDown(sd_time.replace(/-/g,"/"),sx_time.replace(/-/g,"/"),"#colockbox1");
    	 	 }	 
        	 
         }else{
        	// alert("11");
         }  
         read();  
       }  
    });  
}  
var timer;
function countDown(time,systime,id){
	var day_elem = $(id).find('.day');
	var hour_elem = $(id).find('.hour');
	var minute_elem = $(id).find('.minute');
	var second_elem = $(id).find('.second');
	var end_time = new Date(time).getTime(),//月份是实际月份-1
	//sys_second = (end_time-new Date().getTime())/1000;
	sys_second = (end_time-new Date(systime).getTime())/1000;
	//alert(sys_second);
	clearInterval(timer);
	  timer = setInterval(function(){
		if (sys_second >= 1) {
			sys_second -= 1;
			var day = Math.floor((sys_second / 3600) / 24);
			var hour = Math.floor((sys_second / 3600) % 24);
			var minute = Math.floor((sys_second / 60) % 60);
			var second = Math.floor(sys_second % 60);
			day_elem && $(day_elem).text(day);//计算天
			$(hour_elem).text(hour<10?"0"+hour:hour);//计算小时
			$(minute_elem).text(minute<10?"0"+minute:minute);//计算分钟
			$(second_elem).text(second<10?"0"+second:second);//计算秒杀
		} else { 
			clearInterval(timer);
		    //$("#colockbox3").css('display','block'); 
 		    //$("#colockbox2").css('display','none'); 
 		    //$("#colockbox1").css('display','none'); 			
		}
	}, 1000);
}
</script>
        <table class="jj_tb2" width="100%">
            <tbody><tr>
                <td style="width: 116px" align="right">
                    开始时间：
                </td>
                <td align="left" width="140">
                    <span id="kaishshj" style="display:inline-block;width:133px;">${jjinfo.kaishshj}</span>
                </td>
                <td style="width: 104px" align="right">
                    中场时间：
                </td>
                <td align="left" width="140">
                    <span id="zhongchshj" style="display:inline-block;width:125px;">${jjinfo.zhongcsj}</span>
                </td>
                <td align="right" width="110">
                    结束时间： 
                </td>
                <td align="left" width="140">
                    <span id="jieshshj" style="display:inline-block;width:122px;">${jjinfo.jieshshj}</span>
                </td>
            </tr>
            <tr style="display: none">
                <td style="width: 125px" bgcolor="#ffffff">
                    <input name="MAIMLX" value="6" readonly="readonly" id="MAIMLX" class="TpcForm-dropdownlist" style="width:13%;display: none" type="text">
                    <span id="yonghbh">5144</span>
                </td>
            </tr>
        </tbody></table>
        <SCRIPT LANGUAGE="JavaScript">
        function ShowPrice(J) {
 
            var ChuJia = document.getElementById("chuj").value;

            var MinPrice = "${jjinfo.zuidj}";
            var MaxPrice = "${jjinfo.zuigj}";
            var Fd = "${jjinfo.jiagtzfd}";
            var NewPrice="";
            if (J == 1) {
            	NewPrice= (parseInt(ChuJia) + parseInt(Fd)).toString();
            	
            	if (parseInt(NewPrice)>parseInt(MaxPrice)){NewPrice=MaxPrice}

            }
            if (J == 0) {
            	NewPrice= (parseInt(ChuJia) - parseInt(Fd)).toString();
                
            	if (parseInt(NewPrice)<parseInt(MinPrice)){NewPrice=MinPrice}
            	if (parseInt(NewPrice)<0){NewPrice=0}
            }            

            document.getElementById("chuj").value=NewPrice;
            
        }
        //alert("");
 
       
        </SCRIPT>
        <div class="dm_bg">
            <table class="jj_tb3" id="myTable" width="100%">
                <tbody><tr>
                    <td align="right" width="80">
                        <strong>我的代码：</strong>
                    </td>
                    <td align="left" width="60">
                        <span id="MyCode" style="display:inline-block;width:47px;">${qiyid}</span>
                    </td>
                    <td width="20">
                    </td>
                    <td align="right" width="80">
                        降价幅度：
                    </td>
                    <td align="left" width="80">
                        <span id="jiangjfd" style="display:inline-block;width:29px;">${jjinfo.jiagtzfd}</span>(元/吨)
                    </td>
                    <td align="right" width="90">
                        出价(元/吨)
                    </td>
                    <td width="110">
                        <input name="chuj" value="${dqjg}" maxlength="8" id="chuj" class="TpcForm-textbox" onkeypress="javascript:PlusDecimalKeyPress();" style="height:17px;width:91px;" type="text">
                    </td>
                    <td width="25">
                        <input id="BTShangTiao" class="jia_anniu" onclick="ShowPrice('1');" type="button">
                    </td>
                    <td width="25">
                        <input id="BTXiaTiao" onclick="ShowPrice('0');" class="jian_anniu" type="button">
                    </td>
                    <td width="80">
                        <input name="btChuJia" value="出价" onclick="return showca();" id="btchujia" class="cj_anniu" type="button">
                    </td>
                    <td width="">
                    </td>
                </tr>
            </tbody></table>
        </div>
         
        <div class="jj_bt">
            报单信息</div>
        <table class="jj_tb4" width="100%">
            <tbody><tr>
                <td align="right" width="80">
                    <strong>编号：</strong>
                </td>
                <td align="left" width="170">
                    <span id="shangpbh" style="display:inline-block;width:47px;">${jjinfo.baodbh}</span>
                </td>
                <td align="right" width="80">
                    <strong>煤种：</strong>
                </td>
                <td align="left" width="170">
                    <span id="meizh" style="display:inline-block;width:47px;">${jjinfo.meizmc}</span>
                </td>
                <td align="right" width="80">
                    <strong>品种：</strong>
                </td>
                <td align="left" width="170">
                    <span id="pinzh" style="display:inline-block;width:101px;">${jjinfo.pinzmc}</span>
                </td>
            </tr>
            <tr bgcolor="#e8f5fe">
                <td align="right" width="80">
                    <strong>底价：</strong>
                </td>
                <td align="left" width="170">
                    <span id="dijia" style="display:inline-block;width:47px;">${jjinfo.zuidj}</span>元/吨
                </td>
                <td align="right" width="80">
                    <strong>限价：</strong>
                </td>
                <td align="left" width="170">
                    <span id="xianjia" style="display:inline-block;width:47px;">${jjinfo.zuigj}</span>元/吨
                </td>
                <td align="right" width="80">
                    <strong>数量：</strong>
                </td>
                <td align="left" width="170">
                    <span id="shul" style="display:inline-block;width:47px;">${jjinfo.shul}</span>吨
                </td>
            </tr>
            <tr>
                <td align="right" width="80">
                    <strong>指标：</strong>
                </td>
                <td colspan="5" align="left">
                    <span id="zhib" style="display:inline-block;width:584px;">${jjinfo.zhilzb}</span>
                </td><input type=hidden name=baodid value="${jjinfo.sysid}"> <input type=hidden name=jingjr value="${userid}"> <input type=hidden name=danwid value="${qiyid}"><input type=hidden name=maimlx value="${jjinfo.maimlx}">
            </tr>
        </tbody></table>
        <div class="jj_bt">
            实时竞价信息</div>
        <div class=" left_tb">
            <div id="JiaGLXLeft">
            <table class="jj_tb5" width="100%" id="jjtab1">
            <tbody>
            <tr class="jj_tb5_1">
            <td colspan="3">出价记录</td>
            </tr>
            <tr>
            <td><strong>交易商代码</strong></td>
            <td><strong>出价金额</strong></td>
            <td><strong>出价时间</strong></td>
            </tr>
 
            <c:forEach var="jl" items="${cjjl}">
			<tr bgcolor="#fffbd5">
            <td width="130">${jl.danwid}</td>
            <td width="110">${jl.chuj}</td>
            <td width="240">${jl.jingjrq} ${jl.jingjshj} </td>
			</tr>
			</c:forEach>	
 
            </tbody></table></div>
        </div>
       
        <div class="right_tb">
            <div id="JiaGLXRight">
            <table class="jj_tb5" width="100%">
             
            <tr class="jj_tb5_2">
            <td colspan="2">出价记录</td>
            </tr>
            <tr>
            <td width="130">
            <strong>交易代码</strong>
            </td><td width="120">
            <strong>出价</strong></td>
            </tr>
             <tbody id='jjtab2'>
            <tr >

            </tr>
            <c:forEach var="jlz" items="${cjjlz}">
			<tr  >
			<td> ${jlz.bh} </td>
            <td> ${jlz.jg} </td>
			</tr>
			</c:forEach>	            
             </tbody>
             </table></div>
        </div>
    </div>
    </form>
</body>
</html>

